﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data.SqlClient;
using System.Data;
using DTO;  
namespace DAO
{
   public class LoaiTheDA
    {
       public static LoaiThe GetByID(int maID)
       {
           LoaiThe loai = null;
           SqlConnection cn = DataProvider.Connect();
           SqlCommand cmd = new SqlCommand("Proc_LoaiThe_GetById", cn);
           cmd.CommandType = CommandType.StoredProcedure;
           cmd.Parameters.Add(new SqlParameter("@maLoai", maID));
           SqlDataReader dataReader = cmd.ExecuteReader();
           if (dataReader.Read())
           {
               loai = new LoaiThe();
               loai.MaLoai = maID;
               loai.DelFlg = Convert.ToInt32(dataReader["DelFlg"]);
               loai.LastUpdate = Convert.ToDateTime(dataReader["LastUpdate"]);
               loai.GhiChu = Convert.ToString(dataReader["GhiChu"]);
               loai.TenLoai = Convert.ToString(dataReader["TenLoai"]);
           }
           cn.Close();
           return loai;
       }
       public static List<LoaiThe> GetALL()
       {
           List<LoaiThe> lst = new List<LoaiThe>();
           LoaiThe loai = null;
           SqlConnection cn = DataProvider.Connect();
           SqlCommand cmd = new SqlCommand("Proc_LoaiThe_GetALL", cn);
           cmd.CommandType = CommandType.StoredProcedure;
           SqlDataReader dataReader = cmd.ExecuteReader();
           while (dataReader.Read())
           {
               loai = new LoaiThe();
               loai.MaLoai = Convert.ToInt32(dataReader["MaLoai"]);
               loai.DelFlg = Convert.ToInt32(dataReader["DelFlg"]);
               loai.LastUpdate = Convert.ToDateTime(dataReader["LastUpdate"]);
               loai.GhiChu = Convert.ToString(dataReader["GhiChu"]);
               loai.TenLoai = Convert.ToString(dataReader["TenLoai"]);
               lst.Add(loai);
           }
           cn.Close();
           return lst;
       }
    }
}
